package com.sjsoft.Utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;


public class networkUtility {
	private Context context = null;

    private static networkUtility instance = null;

    /**
     * Constructor
     * 
     * @param context
     */
    private networkUtility(Context context)
    {
        this.context = context;
    }

    /**
     * Get class instance
     * 
     * @param context
     * @return
     */
    public static networkUtility getInstance(Context context)
    {
        if (instance == null)
        {
            instance = new networkUtility(context);
        }
        return instance;
    }

    /**
     * Check network connection
     * 
     * @return
     */
    public boolean isNetworkAvailable()
    {
        ConnectivityManager conMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo i = conMgr.getActiveNetworkInfo();
        if (i == null)
        {
            return false;
        }
        if (!i.isConnected())
        {
            return false;
        }
        if (!i.isAvailable())
        {
            return false;
        }
        return true;
    }
}
